import {
    EMAIL_REGISTER,

    PERSONAL_MY_CONTRIBUTIONS,
    PERSONAL_MY_FOLLOWED_USERS,
    PERSONAL_MY_INFO,
    PERSONAL_MY_HAVE_GOODS,
    PERSONAL_MY_WANT_GOODS,
    PERSONAL_INFO,
    PERSONAL_WANT_GOODS,
    PERSONAL_HAVE_GOODS,

    GOODS_CREATE,
    GOODS_UPDATE,
    GOODS_INFO,
    GOODS_LIST_BY_CATEGORY,
    GOODS_HISTORY,
    GOODS_REPORT,
    GOODS_HAVE_TOGGLE,
    GOODS_LIKE_TOGGLE,
    GOODS_WANT_TOGGLE,
    GOODS_SEARCH,

    SERIES_CREATE,
    SERIES_UPDATE,
    SERIES_INFO,
    SERIES_HISTORY,
    SERIES_LIST,

    ROLE_CREATE,
    ROLE_UPDATE,
    ROLE_INFO,
    ROLE_HISTORY,
    ROLE_LIST,

    FOLLOW_FOLLOW,
    FOLLOW_IS_FOLLOWING,
    FOLLOW_STATS,
    FOLLOW_TOGGLE,
    FOLLOW_UNFOLLOW,
    CATEGORY_STATUS_LIST,
    CATEGORY_LIST,
    FEEDBACK_CREATE,

    HOT_RANK_ROLE,
    HOT_RANK_WORK,

    UPDATE_AVATAR,
    UPDATE_USERNAME,
    UPDATE_PHONE,
} from '@/config/url';
import request from '@/utils/request';

// 邮箱注册
export const registerByEmail = (data={}) => {
    return request(EMAIL_REGISTER, {method: 'post', data});
};



// 新增谷子
export const createMerch = (data={}) => {
    return request(GOODS_CREATE, {method: 'post', data});
};
// 更新谷子
export const updateMerch = (data={}) => {
    return request(GOODS_UPDATE, {method: 'put', data});
};
// 谷子列表
export const getMerchList = (data={}) => {
    return request(GOODS_SEARCH, {data});
};
// 谷子详情
export const getMerchInfo = (data={}) => {
    const {id, ...rest} = data;
    return request(GOODS_INFO.replace('{id}', id), {data: rest});
};
// 点赞谷子
export const likeMerch = (data={}) => {
    const {id, ...rest} = data;
    return request(GOODS_LIKE_TOGGLE.replace('{id}', id), {method: 'post', data: rest});
};
// 取消点赞谷子
export const unLikeMerch = (data={}) => {
    return likeMerch(data);
};
// 我有谷子+1
export const haveMerchUp = (data={}) => {
    const {id, ...rest} = data;
    return request(GOODS_HAVE_TOGGLE.replace('{id}', id), {method: 'post', data: rest});
};
// 我有谷子-1
export const haveMerchDown = (data={}) => {
    return haveMerchUp(data);
};
// 我要谷子+1
export const wantMerchUp = (data={}) => {
    const {id, ...rest} = data;
    return request(GOODS_WANT_TOGGLE.replace('{id}', id), {method: 'post', data: rest});
};
// 我要谷子-1
export const wantMerchDown = (data={}) => {
    return wantMerchUp(data);
};
// 谷子变更历史
export const getMerchHistory = (data={}) => {
    const {id, ...rest} = data;
    return request(GOODS_HISTORY.replace('{id}', id), {data: rest});
};
// 举报谷子
export const reportMerch = (data={}) => {
    const {id, ...rest} = data;
    return request(GOODS_REPORT.replace('{id}', id), {method: 'post', data: rest});
};
// 根据分类查询鼓励列表
export const getMerchListByCategory = (data={}) => {
    const {categoryId, ...rest} = data;
    return request(GOODS_LIST_BY_CATEGORY.replace('{id}', categoryId), {data});
};

// 新增作品
export const createWork = (data={}) => {
    return request(SERIES_CREATE, {method: 'post', data});
};
// 更新作品
export const updateWork = (data={}) => {
    return request(SERIES_UPDATE, {method: 'put', data});
};
// 作品详情
export const getWorkInfo = (data={}) => {
    const {id, ...rest} = data;
    return request(SERIES_INFO.replace('{id}', id), {data: rest});
};
// 作品列表
export const getWorkList = (data={}) => {
    return request(SERIES_LIST, {data});
};
// 作品编辑历史
export const getWorkHistory = (data={}) => {
    const {id, ...rest} = data;
    return request(SERIES_HISTORY.replace('{id}', id), {data: rest});
};


// 新增角色
export const createRole = (data={}) => {
    return request(ROLE_CREATE, {method: 'post', data});
};
// 更新角色
export const updateRole = (data={}) => {
    return request(ROLE_UPDATE, {method: 'put', data});
};
// 角色详情
export const getRoleInfo = (data={}) => {
     const {id, ...rest} = data;
    return request(ROLE_INFO.replace('{id}', id), {data: rest});
};
// 角色列表
export const getRoleList = (data={}) => {
    return request(ROLE_LIST, {data});
};
// 角色编辑历史
export const getRoleHistory = (data={}) => {
    const {id, ...rest} = data;
    return request(ROLE_HISTORY.replace('{id}', id), {data: rest});
};
// 作品、角色下谷子列表
export const getMerchListByWorkRole = (data={}) => {
    return request(GOODS_SEARCH, {data});
};


// 获取热门作品TOP20
export const getHotWorkList = (data={}) => {
    return request(HOT_RANK_WORK, {data});
};
// 获取热门角色TOP20
export const getHotRoleList = (data={}) => {
    return request(HOT_RANK_ROLE, {data});
};



// 获取用户信息
export const getUserInfo = (data={}) => {
    const {memberId, ...rest} = data;
    // id存在就是他人查看，id不存在就是自己查看
    const url = !!memberId ? PERSONAL_INFO.replace('{id}', memberId) : PERSONAL_MY_INFO;
    return request(url, {data: rest});
};
// 我有的谷子列表
export const getHaveMerchList = (data={}) => {
    // id存在就是他人查看，id不存在就是自己查看
    const url = !!data.memberId ? PERSONAL_HAVE_GOODS : PERSONAL_MY_HAVE_GOODS;
    return request(url, {data});
};
// 我要的谷子列表
export const getWantMerchList = (data={}) => {
    // id存在就是他人查看，id不存在就是自己查看
    const url = !!data.memberId ? PERSONAL_WANT_GOODS : PERSONAL_MY_WANT_GOODS;
    return request(url, {data});
};
// 我的贡献列表
export const getContribList = (data={}) => {
    return request(PERSONAL_MY_CONTRIBUTIONS, {data});
};
// 我关注的用户列表
export const getFollowUserList = (data={}) => {
    return request(PERSONAL_MY_FOLLOWED_USERS, {data});
};
// 关注用户
export const followUser = (data={}) => {
    return request(FOLLOW_FOLLOW, {data});
};
// 取消关注用户
export const unFollowUser = (data={}) => {
    return request(FOLLOW_UNFOLLOW, {data});
};
// 检查是否已关注
export const checkFollowed = (data={}) => {
    return request(FOLLOW_IS_FOLLOWING, {data});
};
// 获取关注统计
export const getFollowStats = (data={}) => {
    return request(FOLLOW_STATS, {data});
};

// 获取分类列表
export const getCategoryStatusList = (data={}) => {
    return request(CATEGORY_STATUS_LIST, {data});
};
// 获取分类列表
export const getCategoryList = (data={}) => {
    return request(CATEGORY_LIST, {data});
};
// 反馈
export const feedback = (data={}) => {
    return request(FEEDBACK_CREATE, {method: 'post', data});
};

// 更新用户头像
export const updateAvatar = (data={}) => {
    return request(UPDATE_AVATAR, {method: 'put', data});
};
// 更新用户名
export const updateUsername = (data={}) => {
    return request(UPDATE_USERNAME, {method: 'put', data});
};
// 更新手机号
export const updatePhone = (data={}) => {
    return request(UPDATE_PHONE, {method: 'put', data});
};









